package com.example.acroandroiduser;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class TitlepageActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_titlepage);
		Typeface tf = Typeface.createFromAsset(getAssets(), "berlinSans.ttf");
		TextView tv = (TextView) findViewById(R.id.title);
		tv.setTypeface(tf);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.titlepage, menu);
		return true;
	}

	public void login1(View view) {
		startActivity(new Intent(TitlepageActivity.this,
				GameSelectActivity.class));
	}
	
	public void login2(View view) {
		startActivity(new Intent(TitlepageActivity.this,
				GameSelectActivity.class));
	}

	public void loginRuzzle(View view) {
		Button b1 = (Button) findViewById(R.id.createAccount);
		b1.setVisibility(View.GONE);
		Button b2 = (Button) findViewById(R.id.loginAcromania);
		b2.setVisibility(View.GONE);
		Button b3 = (Button) findViewById(R.id.loginFacebook);
		b3.setVisibility(View.GONE);
		Button b4 = (Button) findViewById(R.id.login1);
		b4.setVisibility(View.VISIBLE);
		EditText et1 = (EditText) findViewById(R.id.password_box);
		et1.setVisibility(View.VISIBLE);
		EditText et2 = (EditText) findViewById(R.id.username_box);
		et2.setVisibility(View.VISIBLE);
	}
	
	public void loginFacebook(View view) {
		Button b1 = (Button) findViewById(R.id.createAccount);
		b1.setVisibility(View.GONE);
		Button b2 = (Button) findViewById(R.id.loginAcromania);
		b2.setVisibility(View.GONE);
		Button b3 = (Button) findViewById(R.id.loginFacebook);
		b3.setVisibility(View.GONE);
		Button b4 = (Button) findViewById(R.id.login2);
		b4.setVisibility(View.VISIBLE);
		EditText et1 = (EditText) findViewById(R.id.password_box);
		et1.setVisibility(View.VISIBLE);
		EditText et2 = (EditText) findViewById(R.id.username_box);
		et2.setVisibility(View.VISIBLE);
	}
	
	public void createAccount(View view) {
		Button b1 = (Button) findViewById(R.id.createAccount);
		b1.setVisibility(View.GONE);
		Button b2 = (Button) findViewById(R.id.loginAcromania);
		b2.setVisibility(View.GONE);
		Button b3 = (Button) findViewById(R.id.loginFacebook);
		b3.setVisibility(View.GONE);
		Button b4 = (Button) findViewById(R.id.create);
		b4.setVisibility(View.VISIBLE);
		EditText et1 = (EditText) findViewById(R.id.password_box);
		et1.setVisibility(View.VISIBLE);
		EditText et2 = (EditText) findViewById(R.id.username_box);
		et2.setVisibility(View.VISIBLE);
		
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
	    if (keyCode == KeyEvent.KEYCODE_BACK) {
	    	Button b1 = (Button) findViewById(R.id.create);
			Button b2 = (Button) findViewById(R.id.login1);
			Button b3 = (Button) findViewById(R.id.login2);
			if(b1.getVisibility() == View.VISIBLE || b2.getVisibility() == View.VISIBLE || b3.getVisibility() == View.VISIBLE){
				Button b4 = (Button) findViewById(R.id.createAccount);
				b4.setVisibility(View.VISIBLE);
				Button b5 = (Button) findViewById(R.id.loginAcromania);
				b5.setVisibility(View.VISIBLE);
				Button b6 = (Button) findViewById(R.id.loginFacebook);
				b6.setVisibility(View.VISIBLE);
				EditText et2 = (EditText) findViewById(R.id.username_box);
				et2.setVisibility(View.GONE);
				EditText et1 = (EditText) findViewById(R.id.password_box);
				et1.setVisibility(View.GONE);
				Button b7 = (Button) findViewById(R.id.create);
				b7.setVisibility(View.GONE);
				Button b8 = (Button) findViewById(R.id.login1);
				b8.setVisibility(View.GONE);
				Button b9 = (Button) findViewById(R.id.login2);
				b9.setVisibility(View.GONE);
			}
			else{
				Intent startMain = new Intent(Intent.ACTION_MAIN);
				startMain.addCategory(Intent.CATEGORY_HOME);
				startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(startMain);
			}
	    }
	    return true;
	}

}
